package com.camp.controller;

import java.util.List;

import com.camp.domain.Facilitytype;
import com.camp.service.IFacilitytypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 设施类型Controller
 * 
 * @author ruoyi
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/camp/facilitytype")
public class FacilitytypeController extends BaseController
{
    @Autowired
    private IFacilitytypeService facilitytypeService;

    /**
     * 查询设施类型列表
     */
    @PreAuthorize("@ss.hasPermi('camp:facilitytype:list')")
    @GetMapping("/list")
    public TableDataInfo list(Facilitytype facilitytype)
    {
//        System.out.println("22222222222222");
//        System.out.println(facilitytype);
        startPage();
        List<Facilitytype> list = facilitytypeService.selectFacilitytypeList(facilitytype);
//        System.out.println("type:"+list);
        return getDataTable(list);
    }

    /**
     * 导出设施类型列表
     */
    @PreAuthorize("@ss.hasPermi('camp:facilitytype:export')")
    @Log(title = "设施类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Facilitytype facilitytype)
    {
        List<Facilitytype> list = facilitytypeService.selectFacilitytypeList(facilitytype);
        ExcelUtil<Facilitytype> util = new ExcelUtil<Facilitytype>(Facilitytype.class);
        util.exportExcel(response, list, "设施类型数据");
    }

    /**
     * 获取设施类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:facilitytype:query')")
    @GetMapping(value = "/{ftId}")
    public AjaxResult getInfo(@PathVariable("ftId") String  ftId)
    {
        return success(facilitytypeService.selectFacilitytypeByftId(ftId));
    }

    /**
     * 新增设施类型
     */
    @PreAuthorize("@ss.hasPermi('camp:facilitytype:add')")
    @Log(title = "设施类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Facilitytype facilitytype)
    {
        String id =null;
        UUID uuid = UUID.randomUUID();
        id = uuid.toString();

        //去掉随机ID的短横线
        id = id.replace("-", "");

        //将随机ID换成数字
        int num = id.hashCode();
        //去绝对值
        num = num < 0 ? -num : num;

        id = String.valueOf(num);
        facilitytype.setftId(id);
        return toAjax(facilitytypeService.insertFacilitytype(facilitytype));
    }

    /**
     * 修改设施类型
     */
    @PreAuthorize("@ss.hasPermi('camp:facilitytype:edit')")
    @Log(title = "设施类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Facilitytype facilitytype)
    {
        return toAjax(facilitytypeService.updateFacilitytype(facilitytype));
    }

    /**
     * 删除设施类型
     */
    @PreAuthorize("@ss.hasPermi('camp:facilitytype:remove')")
    @Log(title = "设施类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ftIds}")
    public AjaxResult remove(@PathVariable String[]  ftIds)
    {
        System.out.println("wky222222"+ftIds.toString());
//        System.out.println(ftIds);
        return toAjax(facilitytypeService.deleteFacilitytypeByftIds( ftIds));
    }
}
